package com.kkb.dtg.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;


/**
 * @author: mj
 * @create: 2021-01-21
 * @describe: 统一返回信息封装类
 */
public class RespBean<T> implements Serializable {
    /**
     * 返回的数据
     */
    private T data;

    /**
     * 错误信息
     */
    private Response response = new Response();

    /**
     * 操作状态内置类
     */
    class Response {
        //是否成功
        @JsonProperty("isSuccess")
        private boolean isSuccess = true;
        //错误码
        @JsonProperty("code")
        String code = "200";
        //错误信息
        @JsonProperty("msg")
        String msg = "";

        @Override
        public String toString() {
            return "Response{" +
                    "code='" + code + '\'' +
                    ", msg='" + msg + '\'' +
                    '}';
        }
    }

    public RespBean(T data, boolean isSuccess, String code, String msg) {
        this.data = data;
        this.response.isSuccess = isSuccess;
        this.response.code = code;
        this.response.msg = msg;
    }

    public RespBean(boolean isSuccess, String code, String msg) {
        this.data = null;
        this.response.isSuccess = isSuccess;
        this.response.code = code;
        this.response.msg = msg;
    }

    public RespBean() {
        this.data = null;
    }

    public RespBean(T data){
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @JsonIgnore
    public boolean getSuccess() {
        return response.isSuccess;
    }

    public void setSuccess(boolean isSuccess) {
        response.isSuccess = isSuccess;
    }

    public Response getResponse() {
        return response;
    }

    public void setcode(String code) {
        this.response.code = code;
    }

    public void setmsg(String msg) {
        this.response.msg = msg;
    }

    @Override
    public String toString() {
        return "RespBean{" +
                "data=" + data +
                ", response=" + response +
                '}';
    }
}
